package com.art.base.util;


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

/**
 * 网络Util
 * 
 * @ClassName: NetUtil
 * @Description: 网络相关工具类
 * @author dongtianhao
 * @date 2016年7月12日 下午3:42:15
 *
 */
public class NetUtil {
	private static final String TAG = "artNet";

	/**
	 * 是否联网
	 * 
	 * @param context
	 * @return
	 */
	public static boolean isNetworkAvailable(Context context) {
		ConnectivityManager mgr = (ConnectivityManager) context.getApplicationContext()
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo[] info = mgr.getAllNetworkInfo();
		if (info != null) {
			for (int i = 0; i < info.length; i++) {
				if (info[i].getState() == NetworkInfo.State.CONNECTED) {
					Log.d(TAG, "network is available");
					return true;
				}
			}
		}
		Log.e(TAG, "network is not available");
		return false;
	}
}
